package com.meixiang.adapter.shopping;

import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okhttputils.model.HttpParams;
import com.lzy.okhttputils.request.BaseRequest;
import com.meixiang.R;
import com.meixiang.activity.homes.shopping.GoodsDetailActivity;
import com.meixiang.activity.homes.shopping.ShoppingCartActivity;
import com.meixiang.activity.homes.shopping.StoreGoodsListActivity;
import com.meixiang.activity.homes.shopping.VerifyGoodsOrderActivity;
import com.meixiang.dialog.AlertDialogFragment;
import com.meixiang.dialog.LoadingDialog;
import com.meixiang.dialog.SelectSettleStoreDialog;
import com.meixiang.entity.shopping.CartBalanceStoreEntity;
import com.meixiang.entity.shopping.CartCouponInfoEntity;
import com.meixiang.entity.shopping.CartGoodsEntity;
import com.meixiang.entity.shopping.CartStoreEntity;
import com.meixiang.entity.shopping.result.BalanceAccountResult;
import com.meixiang.entity.shopping.result.CalculateCartPriceResult;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.tool.Tool;
import com.meixiang.util.AbJsonUtil;
import com.meixiang.view.GoodsNumChangeView;
import com.meixiang.view.LineView;
import com.meixiang.view.ShoppingCartGoodsView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 购物车ExpandableListView 适配器
 *
 * @author LZRUI
 */
public class ShoppingCartExpandableAdapter extends BaseExpandableListAdapter implements GoodsNumChangeView.OnNumChangeListener {

    private FragmentActivity mContext;
    private LoadingDialog loadingDialog;
    private OnShoppingCartChangeListener mChangeListener; // 数据变化监听器
    private List<CartStoreEntity> storeList; // 购物车列表数据

    public void refreshData(List<CartStoreEntity> list) {
        if (list != null) {
            storeList = list;
            notifyDataSetChanged();
        }
    }

    /**
     * 点击事件监听器
     */
    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                // 组全选按钮
                case R.id.cb_group_select:
                    int groupPos = (Integer) v.getTag(R.id.group_position);
                    selectGroup(groupPos);
                    break;
                // 满减
                case R.id.ll_coupon:
                    if (Tool.isFastDoubleClick()) return;
                    // TODO 满减
                    String storeId = (String) v.getTag(R.id.store_id);
                    String storeName = (String) v.getTag(R.id.store_name);
                    Intent intStore = new Intent(mContext, StoreGoodsListActivity.class);
                    intStore.putExtra(StoreGoodsListActivity.STORE_ID, storeId);
                    intStore.putExtra(StoreGoodsListActivity.STORE_NAME, storeName);
                    mContext.startActivity(intStore);
                    break;
                // 子选择按钮
                case R.id.cb_child_select:
                    int groupPosition = (Integer) v.getTag(R.id.group_position);
                    int childPosition = (Integer) v.getTag(R.id.child_position);
                    selectChild(groupPosition, childPosition);
                    break;
                // 删除
                case R.id.imgBtn_delete:
                    if (Tool.isFastDoubleClick()) return;
                    final int gPos = (Integer) v.getTag(R.id.group_position);
                    final int cPos = (Integer) v.getTag(R.id.child_position);
                    new AlertDialogFragment.Builder()
                            .setContentText("确认要删除该商品吗？")
                            .setRightBtnText("取消")
                            .setLeftBtnText("确认")
                            .setLeftClickCallBack(new AlertDialogFragment.LeftClickCallBack() {
                                @Override
                                public void dialogLeftBtnClick() {
                                    // TODO 删除商品
                                    changeGoodsNum("0", gPos, cPos);
                                }
                            })
                            .build()
                            .show(mContext.getSupportFragmentManager(), AlertDialogFragment.TAG);
                    break;
                // 查看商品详情
                case R.id.ll_goods:
                    if (Tool.isFastDoubleClick()) return;
                    // TODO 进入商品详情界面
                    String goodsId = (String) v.getTag();
                    Intent intent = new Intent(mContext, GoodsDetailActivity.class);
                    intent.putExtra(GoodsDetailActivity.GOODS_ID, goodsId);
                    mContext.startActivity(intent);
                    break;
                // 结算按钮
                case R.id.tv_settle_accounts:
                    if (Tool.isFastDoubleClick()) return;
                    separateBalance();
                    break;
            }
        }
    };

    public ShoppingCartExpandableAdapter(FragmentActivity context) {
        this.mContext = context;
        loadingDialog = new LoadingDialog(mContext);
    }

    /**
     * 设置购物车数据变化监听器
     *
     * @param changeListener
     */
    public void setOnShoppingCarChangeListener(OnShoppingCartChangeListener changeListener) {
        this.mChangeListener = changeListener;
    }

    /**
     * 获取View的点击事件监听器
     *
     * @return
     */
    public View.OnClickListener getOnClickListener() {
        return this.onClickListener;
    }


    @Override
    public int getGroupCount() {
        return storeList == null ? 0 : storeList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return storeList == null || storeList.get(groupPosition) == null || storeList.get(groupPosition).getCartGoodsList() == null ? 0 : storeList.get(groupPosition).getCartGoodsList().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return storeList.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return storeList.get(groupPosition).getCartGoodsList().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_shopping_cart_group, parent, false);
            viewHolder = new GroupViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (GroupViewHolder) convertView.getTag();
        }

        // TODO checkbook会抢占焦点，导致expandableListView获取点击事件，通过以下两个设置来解决
        viewHolder.cbGroupSelect.setFocusable(false);
        viewHolder.cbGroupSelect.setClickable(true);

        CartStoreEntity storeEntity = storeList.get(groupPosition);
        if (storeEntity != null) {
            viewHolder.tvGroupName.setText(storeEntity.getStoreName());
            // 将当前组编号作为tag存入checkBox中
            viewHolder.cbGroupSelect.setTag(groupPosition);
            // 满减信息
            if (!TextUtils.isEmpty(storeEntity.getCouponInfo())) {
                viewHolder.llCoupon.setVisibility(View.VISIBLE);
                viewHolder.lineView.setVisibility(View.GONE);
                viewHolder.tvCouponType.setText(storeEntity.getCouponTypeInfo());
                viewHolder.tvCouponHint.setText(storeEntity.getCouponInfo());
                viewHolder.llCoupon.setOnClickListener(onClickListener);
                viewHolder.llCoupon.setTag(R.id.store_id, storeEntity.getStoreId());
                viewHolder.llCoupon.setTag(R.id.store_name, storeEntity.getStoreName());
            } else {
                viewHolder.lineView.setVisibility(View.VISIBLE);
                viewHolder.llCoupon.setVisibility(View.GONE);
            }
            // 设置选中情况
            viewHolder.cbGroupSelect.setChecked(storeEntity.isSelected());
        }

        // 设置点击事件
        viewHolder.cbGroupSelect.setOnClickListener(onClickListener);
        viewHolder.cbGroupSelect.setTag(R.id.group_position, groupPosition);

        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_shopping_cart_child, parent, false);
            viewHolder = new ChildViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ChildViewHolder) convertView.getTag();
        }

        viewHolder.cbChildSelect.setFocusable(false);
        viewHolder.cbChildSelect.setClickable(true);
        // 设置点击事件
        viewHolder.cbChildSelect.setOnClickListener(onClickListener);
        viewHolder.imgBtnDelete.setOnClickListener(onClickListener);
        viewHolder.goodsNumChange.setOnNumChangeListener(this);
        viewHolder.llGoods.setOnClickListener(onClickListener);

        CartStoreEntity storeEntity = storeList.get(groupPosition);
        CartGoodsEntity goodsEntity = storeEntity.getCartGoodsList().get(childPosition);

        // 商品数量大于0，才显示商品
        if (goodsEntity != null) {
            if (goodsEntity.isGroup()) {
                // 是套装
                viewHolder.llGoods.setGoodsList(goodsEntity.getGoodsGroupList());
            } else {
                viewHolder.llGoods.setGoods(goodsEntity);
            }
            viewHolder.goodsNumChange.initNum(Integer.valueOf(goodsEntity.getGoodsNum()));
            viewHolder.goodsNumChange.setAutoChangeNum(false);

            // 设置选中情况
            viewHolder.cbChildSelect.setChecked(goodsEntity.isSelected());

            // 便于更新商品数量
            viewHolder.goodsNumChange.setTag(R.id.group_position, groupPosition);
            viewHolder.goodsNumChange.setTag(R.id.child_position, childPosition);

            // 便于子选与组选
            viewHolder.cbChildSelect.setTag(R.id.group_position, groupPosition);
            viewHolder.cbChildSelect.setTag(R.id.child_position, childPosition);

            // 便于查看商品详情
            viewHolder.llGoods.setTag(goodsEntity.getGoodsId());

            // 便于删除某件商品
            viewHolder.imgBtnDelete.setTag(R.id.group_position, groupPosition);
            viewHolder.imgBtnDelete.setTag(R.id.child_position, childPosition);
        }

        if (childPosition == storeEntity.getCartGoodsList().size() - 1) {
            // 最后一条全部显示
            viewHolder.lineView.setMarginLeft(0);
        } else {
            viewHolder.lineView.setMarginLeft(15);
        }

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    @Override
    public void onMinusSuccess(int currentNum, GoodsNumChangeView view) {
        // TODO 商品数量减少成功
        int groupPos = (Integer) view.getTag(R.id.group_position);
        int childPos = (Integer) view.getTag(R.id.child_position);
        if (currentNum > 0) {
            changeGoodsNum(String.valueOf(--currentNum), groupPos, childPos);
        }
    }

    @Override
    public void onAddSuccess(int currentNum, GoodsNumChangeView view) {
        // TODO 商品数量添加成功
        int groupPos = (Integer) view.getTag(R.id.group_position);
        int childPos = (Integer) view.getTag(R.id.child_position);
        if (currentNum > 0) {
            changeGoodsNum(String.valueOf(++currentNum), groupPos, childPos);
        }
    }

    /**
     * 选择子项
     */
    private void selectChild(int groupPosition, int childPosition) {
        CartStoreEntity storeEntity = storeList.get(groupPosition);
        if (storeEntity == null) return;
        List<CartGoodsEntity> childList = storeEntity.getCartGoodsList();
        CartGoodsEntity goods = childList.get(childPosition);
        goods.setSelected(!goods.isSelected());
        childList.set(childPosition, goods);
        storeEntity.setCartGoodsList(childList);
        storeList.set(groupPosition, storeEntity);
        isSelectAllChild(groupPosition);
    }

    /**
     * 反选
     */
    private void isSelectAllChild(int groupPosition) {
        CartStoreEntity storeEntity = storeList.get(groupPosition);
        if (storeEntity == null) return;
        List<CartGoodsEntity> childList = storeEntity.getCartGoodsList();
        int selectChildSize = 0;
        int len = childList.size();
        for (int i = 0; i < len; i++) {
            CartGoodsEntity goods = childList.get(i);
            if (goods.isSelected()) {
                // 选中的子项个数加1
                selectChildSize++;
            } else {
                break;
            }
        }
        if (selectChildSize == len) {
            // 子项全部选中
            storeEntity.setSelected(true);
        } else {
            storeEntity.setSelected(false);
        }
        storeList.set(groupPosition, storeEntity);
        notifyDataSetChanged();
        calculateCartPrice(null, 0, 0);
    }

    /**
     * 选择组
     */
    private void selectGroup(int groupPosition) {
        CartStoreEntity storeEntity = storeList.get(groupPosition);
        if (storeEntity == null) return;
        storeEntity.setSelected(!storeEntity.isSelected());
        List<CartGoodsEntity> childList = storeEntity.getCartGoodsList();
        int len = childList.size();
        for (int i = 0; i < len; i++) {
            CartGoodsEntity goods = childList.get(i);
            // 组选时，子项的状态要跟组的状态一致
            goods.setSelected(storeEntity.isSelected());
            childList.set(i, goods);
        }
        storeEntity.setCartGoodsList(childList);
        storeList.set(groupPosition, storeEntity);
        notifyDataSetChanged();
        calculateCartPrice(null, 0, 0);
    }

    /**
     * 构造重新计算价格的参数
     */
    private Map<String, String> createParamsMap(String storeId, String cartId, String goodsNum, String goodsStorePrice) {
        Map<String, String> goodsMap = new HashMap<>();
        goodsMap.put("storeId", storeId);
        goodsMap.put("cartId", cartId);
        goodsMap.put("goodsNum", goodsNum);
        goodsMap.put("goodsStorePrice", goodsStorePrice);
        return goodsMap;
    }

    /**
     * 非选中状态下编辑商品数量
     */
    private void editCartCount(String goodsStorePrice, String cartId, final String goodsNum, final int groupPos, final int childPos) {
        HttpParams params = new HttpParams();
        params.put("goodsStorePrice", goodsStorePrice);
        params.put("cartId", cartId);
        params.put("goodsNum", goodsNum);

        Log.i("lzrtest", "编辑数量： " + params.toString());

        HttpUtils.post(Config.EDIT_COUNT_CART, ShoppingCartActivity.TAG, params, new HttpCallBack(mContext) {

            @Override
            public void onBefore(BaseRequest request) {
                if (loadingDialog == null || loadingDialog.isShowing()) return;
                loadingDialog.show();
            }

            @Override
            public void onAfter(boolean isFromCache, JSONObject jsonObject, Call call, Response response, Exception e) {
                if (loadingDialog == null) return;
                loadingDialog.dismiss();
            }

            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                refreshCartData(goodsNum, groupPos, childPos);
            }

            @Override
            public void onError(String code, String message) {
                Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 选中商品，选中的状态下编辑商品数量,修改购物车总价格
     */
    private void calculateCartPrice(final String goodsNum, final int groupPosition, final int childPosition) {
        List<Map<String, String>> paramsList = new ArrayList<>(); //  参数集合
        if (storeList == null || storeList.isEmpty()) return;
        // 选中商品
        int storeLen = storeList.size();
        for (int i = 0; i < storeLen; i++) {
            CartStoreEntity store = storeList.get(i);
            int goodsLen = store.getCartGoodsList().size();
            for (int j = 0; j < goodsLen; j++) {
                CartGoodsEntity goods = store.getCartGoodsList().get(j);
                if (goods.isSelected()) {
                    if (TextUtils.isEmpty(goodsNum)) {
                        // 选中操作
                        paramsList.add(createParamsMap(store.getStoreId(), goods.getCartId(), goods.getGoodsNum(), goods.getGoodsStorePrice()));
                    } else {
                        // 修改商品数量
                        if (childPosition == j) {
                            paramsList.add(createParamsMap(store.getStoreId(), goods.getCartId(), goodsNum, goods.getGoodsStorePrice()));
                        } else {
                            paramsList.add(createParamsMap(store.getStoreId(), goods.getCartId(), goods.getGoodsNum(), goods.getGoodsStorePrice()));
                        }
                    }
                }
            }
        }

        HttpParams params = new HttpParams();
        if (paramsList.isEmpty()) {
            if (mChangeListener != null) {
                mChangeListener.onCartSelectNull();
            }
            return;
        }
        params.put("cartString", new Gson().toJson(paramsList));

        Log.i("lzrtest", "计算购物车价格：  " + params.toString());

        HttpUtils.post(Config.CALCULATE_CART_PRICE, ShoppingCartActivity.TAG, params, new HttpCallBack(mContext) {

            @Override
            public void onBefore(BaseRequest request) {
                if (loadingDialog == null || loadingDialog.isShowing()) return;
                loadingDialog.show();
            }

            @Override
            public void onAfter(boolean isFromCache, JSONObject jsonObject, Call call, Response response, Exception e) {
                if (loadingDialog == null) return;
                loadingDialog.dismiss();
            }

            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                CalculateCartPriceResult cartPriceResult = AbJsonUtil.fromJson(result.toString(), CalculateCartPriceResult.class);
                if (cartPriceResult != null) {
                    if (mChangeListener != null) {
                        mChangeListener.onDataChange(cartPriceResult.getGoodsTotalPrice(), cartPriceResult.getCouponTotalPrice());
                    }
                    if (cartPriceResult.getCouponInfoList() != null) {
                        int len = cartPriceResult.getCouponInfoList().size(); // 优惠信息列表长度
                        int storeLen = storeList.size(); // 购物车商店数组的长度
                        for (int i = 0; i < len; i++) {
                            // 刷新此店铺的优惠信息
                            CartCouponInfoEntity couponInfo = cartPriceResult.getCouponInfoList().get(i);
                            for (int j = 0; j < storeLen; j++) {
                                // 通过storeId来匹配相对应的店铺并进行刷新
                                CartStoreEntity store = storeList.get(j);
                                if (store.getStoreId().equals(couponInfo.getStoreId())) {
                                    // 匹配成功，刷新数据
                                    store.setCouponTypeInfo(couponInfo.getCouponTypeInfo());
                                    store.setCouponInfo(couponInfo.getCouponInfo());
                                    if (!TextUtils.isEmpty(goodsNum) && j == groupPosition) {
                                        refreshCartData(goodsNum, groupPosition, childPosition);
                                    }
                                    // 匹配成功，继续设置下一条优惠信息
                                    break;
                                }
                            }
                        }
                        notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onError(String code, String message) {
                Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 按店铺分开提交订单
     */
    private void separateBalance() {
        StringBuilder cardIdsBuilder = new StringBuilder();
        int storeLen = storeList.size();
        for (int i = 0; i < storeLen; i++) {
            CartStoreEntity store = storeList.get(i);
            int goodsLen = store.getCartGoodsList().size();
            for (int j = 0; j < goodsLen; j++) {
                CartGoodsEntity goods = store.getCartGoodsList().get(j);
                if (goods.isSelected()) {
                    cardIdsBuilder.append(goods.getCartId());
                    cardIdsBuilder.append(";");
                }
            }
        }
        Log.i("lzrtest", "结算 cartIds == " + cardIdsBuilder.toString());
        HttpUtils.post(Config.SEPARATE_BALANCE, ShoppingCartActivity.TAG, new HttpParams("cartIds", cardIdsBuilder.toString()), new HttpCallBack(mContext) {

            @Override
            public void onBefore(BaseRequest request) {
                if (loadingDialog != null && !loadingDialog.isShowing())
                    loadingDialog.show();
            }

            @Override
            public void onAfter(boolean isFromCache, JSONObject jsonObject, Call call, Response response, Exception e) {
                if (loadingDialog != null && loadingDialog.isShowing())
                    loadingDialog.dismiss();
            }

            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                try {
                    String storeListJson = result.getString("storeList");
                    List<CartBalanceStoreEntity> storeEntityList = new Gson().fromJson(storeListJson, new TypeToken<List<CartBalanceStoreEntity>>() {
                    }.getType());
                    if (storeEntityList != null && !storeEntityList.isEmpty()) {
                        if (storeEntityList.size() > 1) {
                            SelectSettleStoreDialog.newInstance((ArrayList<CartBalanceStoreEntity>) storeEntityList).show(mContext.getSupportFragmentManager(), SelectSettleStoreDialog.TAG);
                        }else{
                            CartBalanceStoreEntity storeEntity = storeEntityList.get(0);
                            if (storeEntity != null) {
                                balance(storeEntity.getCartIds());
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(String code, String message) {
                Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 结算
     * @param cartIds
     */
    public void balance(String cartIds){
        HttpUtils.post(Config.BALANCE_ACCOUNT, ShoppingCartActivity.TAG, new HttpParams("cartIds", cartIds), new HttpCallBack(mContext) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                BalanceAccountResult balanceAccountResult = AbJsonUtil.fromJson(result.toString(), BalanceAccountResult.class);
                Intent intent = new Intent(mContext, VerifyGoodsOrderActivity.class);
                intent.putExtra(VerifyGoodsOrderActivity.ORDER_DATA, balanceAccountResult);
                mContext.startActivity(intent);
            }

            @Override
            public void onError(String code, String message) {
                Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 改变商品数量
     */
    private void changeGoodsNum(String goodsNum, int groupPos, int childPos) {
        CartStoreEntity store = storeList.get(groupPos);
        CartGoodsEntity goods = store.getCartGoodsList().get(childPos);
        if (goods.isSelected()) {
            calculateCartPrice(goodsNum, groupPos, childPos);
        } else {
            editCartCount(goods.getGoodsStorePrice(), goods.getCartId(), goodsNum, groupPos, childPos);
        }
    }

    /**
     * 修改购物车数据
     */
    private void refreshCartData(String goodsNum, int groupPos, int childPos) {
        CartStoreEntity store = storeList.get(groupPos);
        List<CartGoodsEntity> goodsList = store.getCartGoodsList();
        if (goodsNum.equals("0")) {
            // 如果商品数量为0，删除此条商品数据
            goodsList.remove(childPos);
        } else {
            // 改变商品的数量
            CartGoodsEntity goods = goodsList.get(childPos);
            goods.setGoodsNum(goodsNum);
            goodsList.set(childPos, goods);
        }
        if (goodsList.isEmpty()) {
            // 店铺下的商品数量为0，删除该店铺
            storeList.remove(groupPos);
            if (storeList.isEmpty()) {
                // 店铺列表为空
                if (mChangeListener != null) {
                    mChangeListener.onCartEmpty();
                }
            }
        } else {
            store.setCartGoodsList(goodsList);
            storeList.set(groupPos, store);
        }
        notifyDataSetChanged();
    }

    static class GroupViewHolder {

        @Bind(R.id.cb_group_select)
        CheckBox cbGroupSelect; // 店铺选择按钮
        @Bind(R.id.tv_group_name)
        TextView tvGroupName; // 店铺名称
        @Bind(R.id.ll_coupon)
        LinearLayout llCoupon; // 优惠信息
        @Bind(R.id.line_view)
        LineView lineView; // 分割线线
        @Bind(R.id.tv_coupon_hint)
        TextView tvCouponHint; //  满减、立减提示文本
        @Bind(R.id.tv_coupon_type)
        TextView tvCouponType; // 满减、立减

        GroupViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    static class ChildViewHolder {

        @Bind(R.id.cb_child_select)
        CheckBox cbChildSelect; // 选中按钮
        @Bind(R.id.ll_goods)
        ShoppingCartGoodsView llGoods; // 商品布局
        @Bind(R.id.goods_num_change)
        GoodsNumChangeView goodsNumChange; //  购买数量改变控件
        @Bind(R.id.imgBtn_delete)
        ImageButton imgBtnDelete; // 删除按钮
        @Bind(R.id.line_view)
        LineView lineView; // 分割线

        ChildViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    /**
     * 购物车中商品变化监听接口，方便ExpandableListView与界面上的其他View进行数据同步（比如总价格的同步）
     */
    public interface OnShoppingCartChangeListener {

        /**
         * 商品数据变化回调方法
         *
         * @param totalPrice     总金额
         * @param totalSavePrice 节省的金额
         */
        void onDataChange(String totalPrice, String totalSavePrice);

        /**
         * 购物车被清空回调
         */
        void onCartEmpty();

        /**
         * 全部没选中
         */
        void onCartSelectNull();

        /**
         * 监听当前是否处于全选状态
         * (当前app没有全选按钮)
         * @param isSelectAll 是否全选
         */
        // void onSelectItem(boolean isSelectAll);
    }

}
